<template>
    <div id="">
        <div class="detail">
            <v-detail :inputActive="true" :detailData="inputData" :inputConfig="inputConfig" :rules="rules"
                      ref="input"></v-detail>
        </div>
    </div>
</template>

<script>
import baseMixin from "@/mixins/BaseMixin";
import detail from "commons/Detail";

export default {
    name: "",
    props: {
        inputData: {
            type: Object
        }
    },
    mixins: [baseMixin],
    data() {
        return {
            rules: {
                packkey: [
                    {required: true, trigger: 'blur'},
                ],
                packdescr: [
                    {required: true, trigger: 'blur'},
                ],
                innerpack: [
                    {validator: this.verify, trigger: 'blur'},
                ],
                casecnt: [
                    {validator: this.verify, trigger: 'blur'},
                ],
                pallet: [
                    {validator: this.verify, trigger: 'blur'},
                ],
                cube: [
                    {validator: this.verify, trigger: 'blur'},
                ],
                grosswgt: [
                    {validator: this.verify, trigger: 'blur'},
                ],
                netwgt: [
                    {validator: this.verify, trigger: 'blur'},
                ],
                otherunit1: [
                    {validator: this.verify, trigger: 'blur'},
                ],
                otherunit2: [
                    {validator: this.verify, trigger: 'blur'},
                ],
                packuom3: [
                    {validator: this.packuom3, trigger: 'blur'},
                ],
                packuom2: [
                    {validator: this.packuom2, trigger: 'blur'},
                ],
                packuom1: [
                    {validator: this.packuom1, trigger: 'blur'},
                ],
                packuom4: [
                    {validator: this.packuom4, trigger: 'blur'},
                ],
                packuom5: [
                    {validator: this.packuom5, trigger: 'blur'},
                ],
                packuom6: [
                    {validator: this.packuom6, trigger: 'blur'},
                ],
                packuom7: [
                    {validator: this.packuom7, trigger: 'blur'},
                ],
                packuom8: [
                    {validator: this.packuom8, trigger: 'blur'},
                ],
                packuom9: [
                    {validator: this.packuom9, trigger: 'blur'},
                ],
            },
            whseidflag: false,
            flag: false,
        }
    },
    computed: {
        inputConfig() {
            return [
                [
                    {
                        type: "input",
                        label: this.$t('config.packaging'),
                        props: "packkey",
                        disabled: this.flag
                    },
                    {
                        type: "input",
                        label: this.$t('common.desc'),
                        props: "packdescr",
                        disabled: this.whseidflag
                    },
                ],
                [
                    {
                        type: "",
                        label: this.$t('config.measureUnit'),
                    },
                    {
                        type: "select",
                        label: "",
                        props: "packuom3",
                        disabled: this.whseidflag,
                        options: this.getOptions('querycodeLkup/QUANTITY')
                    },
                    {
                        type: "select",
                        label: "",
                        props: "packuom2",
                        disabled: this.whseidflag,
                        options: this.getOptions('querycodeLkup/QUANTITY')
                    },
                    {
                        type: "select",
                        label: "",
                        props: "packuom1",
                        disabled: this.whseidflag,
                        options: this.getOptions('querycodeLkup/PACKAGE')
                    },
                    {
                        type: "select",
                        label: "",
                        props: "packuom4",
                        disabled: this.whseidflag,
                        options: this.getOptions('querycodeLkup/PACKAGE')
                    },
                    {
                        type: "select",
                        label: "",
                        props: "packuom5",
                        disabled: this.whseidflag,
                        options: this.getOptions('querycodeLkup/VOLUME')
                    },
                    {
                        type: "select",
                        label: "",
                        props: "packuom6",
                        disabled: this.whseidflag,
                        options: this.getOptions('querycodeLkup/WEIGHT')
                    },
                    {
                        type: "select",
                        label: "",
                        props: "packuom7",
                        disabled: this.whseidflag,
                        options: this.getOptions('querycodeLkup/WEIGHT')
                    },
                    {
                        type: "select",
                        label: "",
                        props: "packuom8",
                        disabled: this.whseidflag,
                        options: this.getOptions('querycodeLkup/DIMS')
                    },
                    {
                        type: "select",
                        label: "",
                        props: "packuom9",
                        disabled: this.whseidflag,
                        options: this.getOptions('querycodeLkup/DIMS')
                    },
                ],
                [
                    {
                        type: "",
                        label: this.$t('config.measureunitnum'),
                    },
                    {
                        type: "input",
                        label: "",
                        props: "qty",
                        disabled: true
                    },
                    {
                        type: "input",
                        label: "",
                        props: "innerpack",
                        disabled: this.whseidflag
                    },
                    {
                        type: "input",
                        label: "",
                        props: "casecnt",
                        disabled: this.whseidflag
                    },
                    {
                        type: "input",
                        label: "",
                        props: "pallet",
                        disabled: this.whseidflag
                    },
                    {
                        type: "input",
                        label: "",
                        props: "cube",
                        disabled: this.whseidflag
                    },
                    {
                        type: "input",
                        label: "",
                        props: "grosswgt",
                        disabled: this.whseidflag
                    },
                    {
                        type: "input",
                        label: "",
                        props: "netwgt",
                        disabled: this.whseidflag
                    },
                    {
                        type: "input",
                        label: "",
                        props: "otherunit1",
                        disabled: this.whseidflag
                    },
                    {
                        type: "input",
                        label: "",
                        props: "otherunit2",
                        disabled: this.whseidflag
                    },
                ],
                [
                    {
                        type: "",
                        label: this.$t('config.cartonning'),
                    },
                    {
                        type: "checkbox",
                        label: "",
                        props: "cartonizeuom3",
                        disabled: this.whseidflag
                    },
                    {
                        type: "checkbox",
                        label: "",
                        props: "cartonizeuom1",
                        disabled: this.whseidflag
                    },

                    {
                        type: "checkbox",
                        label: "",
                        props: "cartonizeuom2",
                        disabled: this.whseidflag
                    },
                    {
                        type: "checkbox",
                        label: "",
                        props: "cartonizeuom4",
                        disabled: this.whseidflag
                    },
                    {
                        type: "checkbox",
                        label: "",
                        props: "cartonizeuom5",
                        disabled: this.whseidflag
                    },
                    {
                        type: "checkbox",
                        label: "",
                        props: "cartonizeuom6",
                        disabled: this.whseidflag
                    },
                    {
                        type: "checkbox",
                        label: "",
                        props: "cartonizeuom7",
                        disabled: this.whseidflag
                    },
                    {
                        type: "checkbox",
                        label: "",
                        props: "cartonizeuom8",
                        disabled: this.whseidflag
                    },
                    {
                        type: "checkbox",
                        label: "",
                        props: "cartonizeuom9",
                        disabled: this.whseidflag
                    },

                ],
                [
                    {
                        type: "",
                        label: "",
                    },
                    {
                        type: "",
                        label: this.$t('config.cartonning1'),
                    },
                    {
                        type: "",
                        label: this.$t('config.cartonning2'),
                    },
                    {
                        type: "",
                        label: this.$t('config.cartonning3'),
                    },

                    {
                        type: "",
                        label: this.$t('config.cartonning4'),
                    },
                    {
                        type: "",
                        label: this.$t('config.volume'),
                    },
                    {
                        type: "",
                        label: this.$t('config.gross'),
                    },
                    {
                        type: "",
                        label: this.$t('config.suttle'),
                    },
                    {
                        type: "",
                        label: this.$t('config.cartonning5'),
                    },
                    {
                        type: "",
                        label: this.$t('config.cartonning6'),
                    },
                ],
            ]
        }
    },
    methods: {
        packuom9(rule, value, callback) {
            if (value === '') {
                callback(new Error());
            } else {
                if (this.inputData.otherunit2 > 0) {
                    if (value == " ") {
                        this.$message.error(this.$inputEmptyMes('config.measureUnit'))
                        callback(new Error());
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            }
        },
        packuom8(rule, value, callback) {
            if (value === '') {
                callback(new Error());
            } else {
                if (this.inputData.otherunit1 > 0) {
                    if (value == " ") {
                        this.$message.error(this.$inputEmptyMes('config.measureUnit'))
                        callback(new Error());
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            }
        },
        packuom7(rule, value, callback) {
            if (value === '') {
                callback(new Error());
            } else {
                if (this.inputData.netwgt > 0) {
                    if (value == " ") {
                        this.$message.error(this.$inputEmptyMes('config.measureUnit'))
                        callback(new Error());
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            }
        },
        packuom6(rule, value, callback) {
            if (value === '') {
                callback(new Error());
            } else {
                if (this.inputData.grosswgt > 0) {
                    if (value == " ") {
                        this.$message.error(this.$inputEmptyMes('config.measureUnit'))
                        callback(new Error());
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            }
        },
        packuom5(rule, value, callback) {
            if (value === '') {
                callback(new Error());
            } else {
                if (this.inputData.cube > 0) {
                    if (value == " ") {
                        this.$message.error(this.$inputEmptyMes('config.measureUnit'))
                        callback(new Error());
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            }
        },
        packuom4(rule, value, callback) {
            if (value === '') {
                callback(new Error());
            } else {
                if (this.inputData.pallet > 0) {
                    if (value == " ") {
                        this.$message.error(this.$inputEmptyMes('config.measureUnit'))
                        callback(new Error());
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            }
        },
        packuom3(rule, value, callback) {
            if (value === '') {
                callback(new Error());
            } else {
                if (this.inputData.qty > 0) {
                    if (value == " ") {
                        this.$message.error(this.$inputEmptyMes('config.measureUnit'))
                        callback(new Error());
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            }
        },
        packuom2(rule, value, callback) {
            if (value === '') {
                callback(new Error());
            } else {
                if (this.inputData.innerpack > 0) {
                    if (value == " ") {
                        this.$message.error(this.$inputEmptyMes('config.measureUnit'))
                        callback(new Error());
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            }
        },
        packuom1(rule, value, callback) {
            if (value === '') {
                callback(new Error());
            } else {
                if (this.inputData.casecnt > 0) {
                    if (value == " ") {
                        this.$message.error(this.$inputEmptyMes('config.measureUnit'))
                        callback(new Error());
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            }
        },
        verify(rule, value, callback) {
            if (value === '') {
                callback(new Error());
            } else {
                var re = /^[0-9]*$/;
                let te = value;
                let flag = re.test(te)
                if (flag) {
                    if (value < 0) {
                        this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
                        this.inputData[rule.field] = 0
                        callback(new Error());
                    } else {
                        callback();
                    }
                } else {
                    this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
                    this.inputData[rule.field] = 0
                    callback(new Error());
                }
            }
        },
    },
    mounted() {
        if (Object.keys(this.$store.state.skip).length !== 0) {
            let data = this.$store.state.skip;
            if (data.newFlag) {
                this.flag = false;
            } else {
                this.flag = true;
            }
        } else {
            if (this.$store.state.newFlag) {
                this.flag = false;
            } else {
                this.flag = true;
            }
        }
        if (this.$store.state.wms.toUpperCase().includes('WMWHSE')) {
            //仓库级
            this.flag = this.whseidflag = true;
        }
    },
    watch: {},
    components: {
        "v-detail": detail
    },
}
</script>

<style scoped>

</style>
